﻿<local:ChoBaseWindowEx x:Class="ChoWorkflowDashboard.AddOrEditRolesWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ChoWorkflowDashboard"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:cinchoo="clr-namespace:Cinchoo.Core;assembly=Cinchoo.Core"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:tk="http://schemas.microsoft.com/wpf/2008/toolkit"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        Title="Groups Editor" Height="462" Width="800" MinHeight="440" MinWidth="600"
        ShowInTaskbar="False" Topmost="False"
        BorderBrush="{DynamicResource AccentColorBrush}"
        BorderThickness="1"
        ShowMaxRestoreButton="false" ShowMinButton="false"
                       >
    <Window.Resources>
        <CollectionViewSource x:Key="SortedUsersTableByFullName" Source="{Binding UsersTable}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="FULL_NAME"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </Window.Resources>
    <Grid x:Name="MasterGrid" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="175"/>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid Grid.Row="0" Grid.Column="0" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <GroupBox Grid.Row="0" Grid.Column="0" Header="Add New Group" Name="groupBox3">
                <StackPanel Orientation="Vertical">
                    <xctk:WatermarkTextBox CharacterCasing="Upper" Margin="2" MaxLength="50" Name="txtRoleName" TabIndex="1" Watermark="Enter Group Name"  
                                            local:Masking.Mask="^[A-Za-z0-9_]*$" ToolTip="Accepts only [A-Za-z0-9] characters" />
                    <Button Width="75" Click="btnNewRole_Click" Margin="2" Content="Add New" Name="btnNewRole" TabIndex="2" HorizontalAlignment="Right" />
                </StackPanel>
            </GroupBox>
            <GroupBox Grid.Row="1" Grid.Column="0" Header="Groups" Name="groupBox31">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Row="0" Grid.Column="0" >
                        <ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=RolesTable}" Name="lstRoles" VerticalAlignment="Top" 
                                 SelectionChanged="lstRoles_SelectionChanged" TabIndex="3" MouseDoubleClick="lstRoles_MouseDoubleClick"
                             Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding NAME}" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Grid>
                    <DockPanel Grid.Row="1" Grid.Column="0" Margin="2">
                        <CheckBox DockPanel.Dock="Left" Content="Enabled" FlowDirection="LeftToRight" IsChecked="{Binding ElementName=lstRoles, Path=SelectedItem.Row.ENABLED}" 
                                  Name="chkRoleEnabled" TabIndex="5" VerticalAlignment="Center">
                            <CheckBox.Style>
                                <Style>
                                    <Setter Property="CheckBox.IsEnabled" Value="True"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=lstRoles, Path=SelectedIndex}" Value="-1">
                                            <Setter Property="CheckBox.IsEnabled" Value="false" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </CheckBox.Style>
                        </CheckBox>
                        <Button DockPanel.Dock="Right" Width="75" Content="Delete" Name="btnDeleteRole" TabIndex="4" 
                                Click="btnDeleteRole_Click" HorizontalAlignment="Right">
                            <Button.Style>
                                <Style>
                                    <Setter Property="Button.IsEnabled" Value="True"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=lstRoles, Path=SelectedIndex}" Value="-1">
                                            <Setter Property="Button.IsEnabled" Value="false" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Button.Style>
                        </Button>
                    </DockPanel>
                </Grid>
            </GroupBox>
        </Grid>
        <Grid Grid.Row="0" Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="0" />
                <RowDefinition Height="*" />
                <RowDefinition Height="100" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <GroupBox Grid.Row="0" Grid.Column="0" Name="groupBox2" Header="Avail Users" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="75" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="25" />
                    </Grid.RowDefinitions>
                    <ComboBox Grid.Row="0" Grid.Column="0" HorizontalContentAlignment="Left" 
                              ItemsSource="{Binding Source={StaticResource SortedUsersTableByFullName}}" Name="lstAvailUsers" 
                              TabIndex="6" >
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding DISPLAY_NAME}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                        <ComboBox.Style>
                            <Style>
                                <Setter Property="ComboBox.IsEnabled" Value="True"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=lstRoles, Path=SelectedIndex}" Value="-1">
                                        <Setter Property="ComboBox.IsEnabled" Value="false" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ComboBox.Style>
                    </ComboBox>
                    <Button Grid.Row="0" Grid.Column="1" Margin="2,0,0,0" Content="Add" Name="btnUserAdd" TabIndex="7" 
                            Click="btnUserAdd_Click" >
                        <Button.Style>
                            <Style>
                                <Setter Property="Button.IsEnabled" Value="True"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=lstAvailUsers, Path=SelectedIndex}" Value="-1">
                                        <Setter Property="Button.IsEnabled" Value="false" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>
                </Grid>
            </GroupBox>
            <GroupBox Grid.Row="2" Grid.Column="0" Name="groupBox21" >
                <GroupBox.Header>
                    <DockPanel>
                        <Button Content="Remove" DockPanel.Dock="Right" Name="btnUserRemove" TabIndex="8" Width="75" Click="btnUserRemove_Click" >
                            <Button.Style>
                                <Style>
                                    <Setter Property="Button.IsEnabled" Value="True"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=lstSelectedUsers, Path=SelectedIndex}" Value="-1">
                                            <Setter Property="Button.IsEnabled" Value="false" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding ElementName=lstRoles, Path=SelectedIndex}" Value="-1">
                                            <Setter Property="ListBox.IsEnabled" Value="false" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Button.Style>
                        </Button>
                        <Label>SELECTED USERS</Label>
                    </DockPanel>
                </GroupBox.Header>

                <ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=UserRolesTable}" Name="lstSelectedUsers"
                         MouseDoubleClick="lstSelectedUsers_MouseDoubleClick" TabIndex="9" >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding USER_DISPLAY_NAME}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </GroupBox>
            <GroupBox Grid.Row="0" Grid.Column="1" Header="Avail Policy" Name="groupBox4" >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="75" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="25" />
                    </Grid.RowDefinitions>
                    <Button Content="Add" Grid.Column="1" Margin="2,0,0,0" Name="btnPolicyAdd" TabIndex="11" Click="btnPolicyAdd_Click" >
                        <Button.Style>
                            <Style>
                                <Setter Property="Button.IsEnabled" Value="True"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=lstAvailPolicy, Path=SelectedIndex}" Value="-1">
                                        <Setter Property="Button.IsEnabled" Value="false" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding ElementName=lstRoles, Path=SelectedIndex}" Value="-1">
                                        <Setter Property="ListBox.IsEnabled" Value="false" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>
                    <ComboBox ItemsSource="{Binding Path=PolicyTable}" Name="lstAvailPolicy" 
                          TabIndex="10" >
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding POLICY_DESC}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                    <ComboBox.Style>
                        <Style>
                            <Setter Property="ComboBox.IsEnabled" Value="True"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding ElementName=lstRoles, Path=SelectedIndex}" Value="-1">
                                    <Setter Property="ComboBox.IsEnabled" Value="false" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </ComboBox.Style>
                </ComboBox>
                </Grid>
            </GroupBox>
            <GroupBox Grid.Row="2" Grid.Column="1" Name="groupBox41">
                <GroupBox.Header>
                    <DockPanel>
                        <Button Content="Remove" DockPanel.Dock="Right" Name="btnPolicyRemove" TabIndex="12" Width="75" Click="btnPolicyRemove_Click" >
                            <Button.Style>
                                <Style>
                                    <Setter Property="Button.IsEnabled" Value="True"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=lstSelectedPolicy, Path=SelectedIndex}" Value="-1">
                                            <Setter Property="Button.IsEnabled" Value="false" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding ElementName=lstRoles, Path=SelectedIndex}" Value="-1">
                                            <Setter Property="ListBox.IsEnabled" Value="false" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Button.Style>
                        </Button>
                        <Label>SELECTED POLICY</Label>
                    </DockPanel>
                </GroupBox.Header>
                <ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding Path=RolePolicyTable}" Name="lstSelectedPolicy" 
                         MouseDoubleClick="lstSelectedPolicy_MouseDoubleClick" TabIndex="13" >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding POLICY_DESC}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </GroupBox>
            <GroupBox Grid.Row="3" Grid.ColumnSpan="2" Header="Comments" Name="groupBox5" DockPanel.Dock="Left" >
                <xctk:WatermarkTextBox MaxLength="50" Name="txtComments" TabIndex="1" Watermark="Please double click to add comments..." TextWrapping="Wrap" 
                                       Text = "{Binding ElementName=lstRoles, Path=SelectedItem.Row.COMMENT, UpdateSourceTrigger=PropertyChanged}" ToolTip="Please double click to edit comments..." MouseDoubleClick="txtComments_MouseDoubleClick" 
                                       />
            </GroupBox>

        </Grid>
        <DockPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="2">
            <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" >
                <Button Content="Cancel" Margin="2" IsCancel="True" Name="btnCancel" Width="75" Click="btnCancel_Click" TabIndex="15" />
                <Button Margin="2" Content="OK" IsDefault="True" Name="btnOK" Width="75" Click="btnOK_Click" TabIndex="14" />
            </StackPanel>
        </DockPanel>
    </Grid>
</local:ChoBaseWindowEx>
